package com.nova.view;

import com.nova.source.R;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

public class NovaButtonDialog
{
	private Dialog mDialog;
	private ViewGroup mContent;
	private TextView mTextView;
	private Button leftButton;
	private Button rightButton;
	private OnButtonListener buttonListener;

	public NovaButtonDialog(Context context)
	{
		this.mDialog = new Dialog(context, R.style.dialog);
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.dialog_with_botton, null);
		this.mContent = ((ViewGroup) view.findViewById(R.id.content));
		this.mTextView = ((TextView) view.findViewById(R.id.textview));
		this.leftButton = ((Button) view.findViewById(R.id.left));
		this.leftButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v)
			{
				if (NovaButtonDialog.this.buttonListener != null)
					NovaButtonDialog.this.buttonListener
							.onLeftButtonClick(NovaButtonDialog.this);
			}
		});
		this.rightButton = ((Button) view.findViewById(R.id.right));
		this.rightButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v)
			{
				if (NovaButtonDialog.this.buttonListener != null)
					NovaButtonDialog.this.buttonListener
							.onRightButtonClick(NovaButtonDialog.this);
			}
		});
		this.mDialog.setCancelable(false);
		this.mDialog.setContentView(view);
		this.mDialog.show();
	}

	public void setView(View v)
	{
		this.mContent.removeAllViews();
		this.mContent.addView(v);
	}

	public void setText(String text)
	{
		this.mTextView.setText(text);
	}

	public void setText(int textID)
	{
		this.mTextView.setText(textID);
	}

	public void setLeftButtonText(String text)
	{
		this.leftButton.setText(text);
	}

	public void setLeftButtonText(int textID)
	{
		this.leftButton.setText(textID);
	}

	public void setRightButtonText(String text)
	{
		this.rightButton.setText(text);
	}

	public void setRightButtonText(int textID)
	{
		this.rightButton.setText(textID);
	}

	public void setRightButtonTextColor(int color)
	{
		this.rightButton.setTextColor(color);
	}

	public void show()
	{
		this.mDialog.show();
	}

	public void cancel()
	{
		this.mDialog.cancel();
	}

	public OnButtonListener getButtonListener()
	{
		return this.buttonListener;
	}

	public void setButtonListener(OnButtonListener buttonListener)
	{
		this.buttonListener = buttonListener;
	}

	public static abstract interface OnButtonListener
	{
		public abstract void onLeftButtonClick(
				NovaButtonDialog paramHemaButtonDialog);

		public abstract void onRightButtonClick(
				NovaButtonDialog paramHemaButtonDialog);
	}

}
